package game;

import java.awt.image.BufferedImage;
import java.io.File;

import system.Actor;
import system.AnimatedSprite;
import system.TextHandler;

public class Interface {
	private int score;
	private int scoreDisplay;
	private TextHandler scoreTextHandler;
	
	AnimatedSprite frame;
	AnimatedSprite HPBar;
	Actor hp;
	
	int playerHp;         // where the Hp should be at, if done animating.
	
	public Interface(TextHandler textHandler){
		score = 0;
		scoreDisplay = 0;
		scoreTextHandler = textHandler;
		scoreTextHandler.setText(Integer.toString(0));
		try {
			scoreTextHandler.update();
		} catch (Exception e1) {
		}
		
		playerHp = 100;		
		try {
			frame = new AnimatedSprite(new File("assets/sprites/interface.png"), 480, 20, false, 0);
			HPBar = new AnimatedSprite(new File("assets/sprites/hp.png"), 100, 4, false, 0);
			hp = new Actor("HP Bar", HPBar, 65, 258, 0, 0, 0);
		} catch (Exception e){
			System.out.println("error opening interface.png");
			System.exit(0);
		}
	}
	
	public void addScore(int points){
		score += points;
	}
	
	public void update(){
		frame.update();
		scoreTextHandler.update();
		
		if(hp.sprite.getFrameIndex() < 100 - playerHp){
			hp.setSprite(hp.sprite.getFrameIndex() + 1);
		}
		else if(hp.sprite.getFrameIndex() > 100 - playerHp){
			hp.setSprite(hp.sprite.getFrameIndex() - 1);
		}
		
		if(score > scoreDisplay){
			scoreDisplay += 10;
			scoreTextHandler.setText(Integer.toString(scoreDisplay));
		}
	}
	
	public BufferedImage getFrame(){
		return frame.getImage();
	}
	public BufferedImage getHPBar(){
		return HPBar.getImage();
	}

	public void setHPBar(int newHp) {
		playerHp = newHp;
		if (playerHp < 0){
			playerHp = 0;
		}
	}
	
	public TextHandler getScoreTextHandler(){
		return scoreTextHandler;
	}

	public int getScore() {
		return score;
	}

}
